package com.ruoyi.zhgd.controller;

import java.util.List;
import java.util.Arrays;
import java.util.Map;

import cn.dev33.satoken.annotation.SaCheckLogin;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;

import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.zhgd.domain.vo.ZjExperimentBindingVo;
import com.ruoyi.zhgd.domain.bo.ZjExperimentBindingBo;
import com.ruoyi.zhgd.service.IZjExperimentBindingService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 试验数据绑定
 *
 * @author cj
 * @date 2023-10-20
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/zhgd/experimentBinding")
public class ZjExperimentBindingController extends BaseController {

    private final IZjExperimentBindingService iZjExperimentBindingService;

    /**
     * 查询试验数据绑定列表
     */
    @SaCheckLogin
    @GetMapping("/list")
    public TableDataInfo<ZjExperimentBindingVo> list(ZjExperimentBindingBo bo, PageQuery pageQuery) {
        return iZjExperimentBindingService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出试验数据绑定列表
     */
    @SaCheckLogin
    @Log(title = "试验数据绑定", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ZjExperimentBindingBo bo, HttpServletResponse response) {
        List<ZjExperimentBindingVo> list = iZjExperimentBindingService.queryList(bo);
        ExcelUtil.exportExcel(list, "试验数据绑定", ZjExperimentBindingVo.class, response);
    }

    /**
     * 获取试验数据绑定详细信息
     *
     * @param id 主键
     */
    @SaCheckLogin
    @GetMapping("/{id}")
    public R<ZjExperimentBindingVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iZjExperimentBindingService.queryById(id));
    }

    /**
     * 新增试验数据绑定
     */
    @SaCheckLogin
    @Log(title = "试验数据绑定", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ZjExperimentBindingBo bo) {
         iZjExperimentBindingService.insertByBo(bo);
        return R.ok();
    }

    /**
     * 修改试验数据绑定
     */
    @SaCheckLogin
    @Log(title = "试验数据绑定", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ZjExperimentBindingBo bo) {
        return toAjax(iZjExperimentBindingService.updateByBo(bo));
    }

    /**
     * 删除试验数据绑定
     *
     * @param ids 主键串
     */
    @SaCheckLogin
    @Log(title = "试验数据绑定", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iZjExperimentBindingService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

    /**
     * 已关联试验数据分页
     * @param bo
     * @param pageQuery
     * @return
     */
    @SaCheckLogin
    @GetMapping("/page")
    public TableDataInfo<Map<String, Object>> page(ZjExperimentBindingBo bo, PageQuery pageQuery) {
        return iZjExperimentBindingService.page(bo, pageQuery);
    }

    /**
     * 取消关联
     *
     * @param id 主键
     */
    @SaCheckLogin
    @DeleteMapping("/cancel/{id}")
    public R<Void> cancel(@NotNull(message = "主键不能为空")
                                            @PathVariable String id) {
        iZjExperimentBindingService.cancel(id);
        return R.ok();
    }
}
